package com.fw.system.admin.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fw.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.fw.common.IdXD;
import com.fw.system.admin.mapper.TbUserMapper;
import com.fw.system.admin.domain.TbUser;
import com.fw.system.admin.service.ITbUserService;
import com.fw.utils.DateUtils;
/**
 * 客户端用户Service业务层处理
 * 
 * @author yanwei
 * @date 2023-04-04
 */
@Service
public class TbUserServiceImpl extends ServiceImpl<TbUserMapper, TbUser> implements ITbUserService
{
    @Autowired
    private TbUserMapper tbUserMapper;

    @Autowired
    private IdXD idXD;

    /**
     * 查询客户端用户
     * 
     * @param id 客户端用户ID
     * @return 客户端用户
     */
    @Override
    public TbUser selectTbUserById(String id)
    {
        return tbUserMapper.selectTbUserById(id);
    }

    /**
     * 查询客户端用户列表
     * 
     * @param tbUser 客户端用户
     * @return 客户端用户
     */
    @Override
    public List<TbUser> selectTbUserList(TbUser tbUser)
    {
        return tbUserMapper.selectTbUserList(tbUser);
    }

    /**
     * 新增客户端用户
     * 
     * @param tbUser 客户端用户
     * @return 结果
     */
    @Override
    public int insertTbUser(TbUser tbUser)
    {
        tbUser.setCreateTime(DateUtils.getNowDate());
        tbUser.setId(idXD.nextId());
        return tbUserMapper.insertTbUser(tbUser);
    }

    /**
     * 修改客户端用户
     * 
     * @param tbUser 客户端用户
     * @return 结果
     */
    @Override
    public int updateTbUser(TbUser tbUser)
    {
        tbUser.setUpdateTime(DateUtils.getNowDate());
        return tbUserMapper.updateTbUser(tbUser);
    }

    /**
     * 批量删除客户端用户
     * 
     * @param ids 需要删除的客户端用户ID
     * @return 结果
     */
    @Override
    public int deleteTbUserByIds(String[] ids)
    {
       return update(Wrappers.<TbUser>lambdaUpdate().in(TbUser::getId,Arrays.asList(ids)).set(TbUser::getIsState,0)) ? 1 :0;
        //return tbUserMapper.deleteTbUserByIds(ids);
    }

    /**
     * 删除客户端用户信息
     * 
     * @param id 客户端用户ID
     * @return 结果
     */
    @Override
    public int deleteTbUserById(String id)
    {
        return update(Wrappers.<TbUser>lambdaUpdate().eq(TbUser::getId,id).set(TbUser::getIsState,0)) ? 1 :0;
    }
}
